﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Data.Entity;

namespace Elf.Data.Entity.Interfaces
{
    /// <summary>
    /// Interface for a repository.
    /// </summary>
    /// <typeparam name="TEntity">The type of the entity.</typeparam>
    /// <typeparam name="TContext">The type of the context.</typeparam>
    public interface IRepository<TEntity, TContext>
        where TEntity : class, IEntityBase, new()
        where TContext : ContextBase, new()
    {
        /// <summary>
        /// Finds all entities for a given type.
        /// </summary>
        /// <returns></returns>
        IList<TEntity> FindAll();
        /// <summary>
        /// Finds all entities for a given type by a given expression.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <returns></returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "Generic functionality")]
        IList<TEntity> FindBy(Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// Finds all entities for a given type by its primary key.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        TEntity FindById(object id);
        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="newEntity">The entity.</param>
        void Add(TEntity entity);
        /// <summary>
        /// Removes the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        void Remove(TEntity entity);
        /// <summary>
        /// Return the DbSet of the specified entity.
        /// </summary>
        /// <returns></returns>
        IDbSet<TEntity> DbSet();
    }
}
